//
//  RLTabController.m
//  RelaxLinkProduct
//
//  Created by relax on 2017/11/20.
//  Copyright © 2017年 relax. All rights reserved.
//

#import "RLTabController.h"
#import "RLTabBar.h"
#import "RLShowContrller.h" // 附近的人
#import "RLMeController.h" // 我的
#import "RLLiveController.h" // 直播
#import "RLNavigationController.h" // 导航控制器


@interface RLTabController () <RLTabBarDelegate>

@end

@implementation RLTabController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabBar.translucent = NO;
    // 准备子视图
    [self prepareChildController];
    // 准备 tabBar
    [self prepareBar];
    
    [self removeBarButtonItem];
    
}

#pragma mark - 删除 tabController 自定义的 tabBarButtonItem
- (void)removeBarButtonItem {
    for (UIView *view in self.tabBar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [view removeFromSuperview];
        }
    }
}

#pragma mark - 定义 bar
- (void)prepareBar {
    [self.tabBar setShadowImage:[UIImage new]];
    [self.tabBar setBackgroundImage:[UIImage new]];
    RLTabBar *bar = [[RLTabBar alloc] initWithFrame:self.tabBar.bounds];
    [self.tabBar addSubview:bar];
    //[self setValue:bar forKey:@"tabBar"];
    
    // 设置代理
    bar.delegate = self;
}



#pragma mark - 准备子视图
- (void)prepareChildController {
    RLLiveController *liveVC = [RLLiveController new]; // 我的直播
    RLNavigationController *naviController = [[RLNavigationController alloc] initWithRootViewController:liveVC];
    RLMeController *meVC = [UIStoryboard storyboardWithName:@"RLMeController" bundle:nil].instantiateInitialViewController;
    // RLShowContrller *showVC = [RLShowContrller new];
    
    self.viewControllers = @[naviController, meVC];
}


#pragma mark - RLTabBarDelegate
- (void)tabBar:(RLTabBar *)tabBar didSelectedButton:(TabBarButtonItem)item {
    // 切换 tabBar 控制器
    if (item != TabBarButtonItemCamera) {
        self.selectedIndex = item % TabBarButtonItemLive; // 枚举值从100开始的。
    } else {
        // 开启直播
        RLShowContrller *showController = [[RLShowContrller alloc] init];
        [self presentViewController:showController animated:YES completion:nil];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
